-- not_condition_sequence
--
local import = import
---@type behavior_ret
local bret = import('bt/bt_plugin/behavior3/behavior_ret')

local M = {
    name = "NoConditionSequence",
    type = "Composite",
    desc = "无条件顺序执行",
    args = {
        --{ name = "str", type = "string", desc = "变量描述" }
    },
    doc = [[
        + 一直往下执行,直到执行完所有子节点
    ]],
}

function M.run(node, env, value)
    local last_idx, last_ret = node:resume(env)
    if last_idx then
        if last_ret == bret.RUNNING then
            return last_ret
        end
        last_idx = last_idx + 1
    else
        last_idx = 1
    end

    for i = last_idx, #node.children do
        local child = node.children[i]
        local r = child:run(env)
        if r == bret.RUNNING then
            return node:yield(env, i)
        end
    end
    return bret.SUCCESS
end

return M
